# 8）房屋朝向（雷达图）【东、南、西、北、东北、西北、东南、西南共八个方位】
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Radar

df_tb = pd.read_excel('data_clean.xlsx')
locations = [location for location in df_tb['dire'].value_counts().items()]

x_data =[]
y_data = []
for i in range(len(locations)):
    if locations[i][0] ==0:
        x_data.append("不确定")
    else:
        x_data.append(locations[i][0])
    y_data.append(locations[i][1])

print(x_data)
print(y_data)

# c = (
#     Radar()
#     .add_schema(
#         schema=x_data
#     )
#     .add("实际开销", y_data)
#     .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
#     .set_global_opts(
#         legend_opts=opts.LegendOpts(selected_mode="single"),
#         title_opts=opts.TitleOpts(title="Radar-单例模式"),
#     )
#     .render("radar_selected_mode.html")
# )
"""
['南', '东南', '东', '北', '西南', '西', '西北', '东北', '南北', '东西', '不确定']
[12006, 10196, 4512, 2070, 2017, 759, 554, 390, 365, 38, 2]
"""
v1 = [[4512,12006,759,2070,10196,2017,554,390]]
(
    Radar(init_opts=opts.InitOpts(width="1280px", height="720px", bg_color="#CCCCCC"))
    .add_schema(
        schema=[
            opts.RadarIndicatorItem(name="东", max_=5000),
            opts.RadarIndicatorItem(name="南", max_=12100),
            opts.RadarIndicatorItem(name="西", max_=800),
            opts.RadarIndicatorItem(name="北", max_=2100),
            opts.RadarIndicatorItem(name="东南", max_=10200),
            opts.RadarIndicatorItem(name="西南", max_=2100),
            opts.RadarIndicatorItem(name="西北", max_=600),
            opts.RadarIndicatorItem(name="东北", max_=400),
        ],
        splitarea_opt=opts.SplitAreaOpts(
            is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
        ),
        textstyle_opts=opts.TextStyleOpts(color="#fff"),
    )
    .add(
        series_name="预算分配（Allocated Budget）",
        data=v1,
        linestyle_opts=opts.LineStyleOpts(color="#CD0000"),
    )
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(
        legend_opts=opts.LegendOpts(selected_mode="single"),
        title_opts=opts.TitleOpts(title="Radar-单例模式"),
    )
    .render("basic_radar_chart.html")
)